import logging

import allure
from appium.webdriver.common.appiumby import AppiumBy

from base.base_page import BasePage


class GalleryPage(BasePage):

    _file_count_locator = (AppiumBy.XPATH, "//*[@resource-id='com.pi.pilot.gallery:id/tv_count']")
    _setting_locator = (AppiumBy.XPATH, "//*[@resource-id='com.pi.pilot.gallery:id/iv_menu_setting']")
    _setting_del_locator = (AppiumBy.XPATH, "//*[@text='删除']")
    _setting_stitch_locator = (AppiumBy.XPATH, "//*[@text='拼接']")
    _del_locator = (AppiumBy.XPATH, "//*[@resource-id='com.pi.pilot.gallery:id/iv_delete']")
    _del_confirm_locator = (AppiumBy.XPATH, "//*[@text='删除']")
    _only_file_locator = (AppiumBy.XPATH, "//*[@resource-id='com.pi.pilot.gallery:id/iv_thumbnail']")

    def get_file_count(self):
        self.wait_for_one_second(5)
        count = int(self.find_element_text(self._file_count_locator))
        return count

    def del_only_file(self):
        self.find_and_click(self._setting_locator)
        self.find_and_click(self._setting_del_locator)
        self.find_and_click(self._only_file_locator)
        self.find_and_click(self._del_locator)
        self.find_and_click(self._del_confirm_locator)
        self.wait_for_one_second()
        return self

